using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace System.IPod.Music
{
	// Database
	[StructLayout(LayoutKind.Sequential, Pack=1)]
	unsafe struct Mhbd
	{
		public int TotalLength;
		public int Reserved;
		public int Version;
		public int ChildCount;
		public long Id;
		public int Reserved2;
		public long Reserved3;
		public fixed byte Reserved4[26];
		public short Language;
		public long PersistentId;
				
		public unsafe void Read(BinaryReader reader)
		{
			MhHeader header = new MhHeader();
			header.Read(reader);
			Debug.Assert(header.Identifier[0] == 0x6D &&
				header.Identifier[1] == 0x68 &&
				header.Identifier[2] == 0x62 &&
				header.Identifier[3] == 0x64,
				"Mhdb missmatch");
			
			byte[] data = reader.ReadBytes(header.Length - sizeof(MhHeader));
			fixed (byte* pData = data)
			{
				this = *(Mhbd*)pData;
			}
		}

		public void Write(BinaryWriter writer)
		{
			//byte[] data = StructUtil.GetBytes(this);
			//writer.Write(data);

			//int count = HeaderLength - sizeof(Mhbd);
			//for (int i = 0; i < count; i++)
			//    writer.Write((byte)0);
		}
	}
}
